package com.whiteseason.sortdemo;

/**
 * 希尔排序
 */
public class ShellSort {
    public int[] count(int[] arr){
        double len = arr.length;
        for (double gap = Math.floor(len / 2); gap > 0;gap = Math.floor(gap / 2)){  //对数组进行分组
            for (double i = gap; i < len ;i++){     //这里是每个分组组交替进行排序
                double j = i;
                int current = arr[new Double(j).intValue()];
                while(((j - gap) >= 0) && (arr[new Double(j - gap).intValue()] > current)){
                    arr[(int) j] = arr[(int)j - (int)gap];
                    j = j - gap;
                }
                arr[new Double(j).intValue()] = current;
            }
        }
        return arr;
    }
    public static void main(String[] args) {
        int[] arr =  {1, 9, 7, 4, 2, 15, 23, 77, 24, 86};
        arr = new ShellSort().count(arr);
        for (int i:
             arr) {
            System.out.println(i);
        }
    }
}
